import { createStore } from "vuex";

export default createStore({
    state:{
        //用户信息
        loginUserInfo : null,
        //是否需要登录
        showLogin : false,
        //板块信息
        boardList:[],
        //当前一级板块
        currentPBoardId:0,
        //当前二级板块
        currentBoardId:0,

    },
    getters:{
        getLoginUserInfo:(state)=>{
            return state.loginUserInfo
        },
        getBoardList:(state)=>{
            return state.boardList;
        },
        getSubBoardList:(state)=>(boardId)=>{
            let board = state.boardList.find(item=>{
                return item.boardId == boardId
            });
            return board ?board.children:[]
        },
        getCurrentPBoardId:(state)=>{
            return state.currentPBoardId
        },
        getCurrentBoardId:(state)=>{
            return state.currentBoardId
        },
    },
    mutations:{
        updateLoginUserInfo(state,value){
            state.loginUserInfo = value
        },
        showLogin(state,value){
            state.showLogin = value
        },
        saveBoardList(state,value){
            state.boardList = value
        },
        setCurrentPBoardId(state,value){
            state.currentPBoardId = value
        },
        setCurrentBoardId(state,value){
            state.currentBoardId = value
        },

    },
    actions:{
        
    },
    modules:{

    }
})